<template>
  <div class="wrapper example15-container">
    <!-- 返回区域 -->
    <div
      class="back-box"
      @click="$router.go(-1)"
    >返回</div>

    <!-- 标题区域 -->
    <h1 class="title-box">15、provide和inject</h1>

    <!-- 实例区域 -->
    <div class="example15-box">
      <h3>我是爷组件 {{ name }}----{{ price }}</h3>
      <Son></Son>
    </div>
  </div>
</template>

<script>
import Son from '@/components/Son.vue';
import { provide, reactive, toRefs } from 'vue';

export default {
  name: 'Example15',
  components: {
    Son
  },
  setup() {
    // 数据
    const car = reactive({
      name: '法拉利',
      price: '400W'
    });

    // 给自己的后代传递数据
    provide('car', car);

    return {
      ...toRefs(car)
    };
  }
};
</script>

<style lang="scss" scoped>
.example15-container {
  // 返回区域
  & > .back-box {
    width: 50px;
    height: 23px;
    line-height: 20px;
    text-align: center;
    background-color: #efefef;
    margin-bottom: 20px;
    font-size: 14px;
    border: 1px solid #767676;
    border-radius: 4px;
    cursor: pointer;
  }

  // 标题区域
  & > .title-box {
    margin-bottom: 30px;
  }

  // 实例区域
  & > .example15-box {
    background-color: gray;
    padding: 30px;

    & > h3 {
      margin-bottom: 30px;
    }
  }
}
</style>
